(define (modular-exp x e m)
  ;; x^e mod m
  (cond ((= e 0) 1)
        ((= e 1) (modulo x m))
        (else
         (let* ((y (modular-exp x (quotient e 2) m))
                (z (* y y)))
           (modulo (if (odd? e) (* x z) z) m)))))
